/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */
package org.jaxson.examples.charts.customchart;

import java.awt.Color;

import org.jaxson.struts.charts.AbstractChartRenderer;
import org.jaxson.struts.charts.ChartFormat;
import org.jaxson.struts.charts.bar.BarChartFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.Dataset;

/**
 * @author Joe Maisel
 *
 */
public class WaterfallChartRenderer extends AbstractChartRenderer
{

	/**
	 * @see org.jaxson.struts.charts.AbstractChartRenderer#render(org.jfree.data.general.Dataset, org.jaxson.struts.charts.ChartFormat)
	 */
	@Override
	public JFreeChart render( Dataset dataset, ChartFormat f )
	{
		BarChartFormat format = (BarChartFormat)f;
        final JFreeChart result = ChartFactory.createWaterfallChart(
                format.getTitle(),
                format.getCategoryLabel(),
                format.getValueLabel(),
                (CategoryDataset)dataset,
                format.getOrientation(),
                true,
                true,
                false
            );
        
        final CategoryPlot plot = result.getCategoryPlot();
        plot.setBackgroundPaint(format.getBackgroundColor());
        plot.setRangeGridlinePaint(Color.white);
        plot.setRangeGridlinesVisible(true);
        
        final BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);
        
		return result;
	}

}
